package com.vhans.bapi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.vo.groupmsg.GroupMsgLastVO;
import com.vhans.db.model.vo.groupmsg.GroupMsgVO;
import com.vhans.db.model.vo.msg.MsgLastVO;
import com.vhans.db.service.ICGroupMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 群聊天信息Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "群聊天信息模块")
@RestController
@RequestMapping("/groupMsg")
public class GroupMsgController extends BaseController {
    @Autowired
    private ICGroupMsgService groupMsgService;

    /**
     * 获取群最后一条消息
     *
     * @param groupId 群id
     * @return {@link MsgLastVO} 最后一条消息
     */
    @SaCheckLogin
    @ApiOperation(value = "获取群最后一条消息")
    @GetMapping("/getLastGroupMsg")
    public Result<GroupMsgLastVO> getLastGroupMsg(Integer groupId) {
        return Result.success(groupMsgService.getLastGroupMsg(groupId));
    }

    /**
     * 查询最近的群消息
     *
     * @param groupId 群id
     * @return {@link GroupMsgVO} 群消息列表
     */
    @SaCheckLogin
    @ApiOperation(value = "获取最近的群消息")
    @GetMapping("/listRecent")
    public TableDataInfo listRecent(Integer groupId) {
        startPage();
        List<GroupMsgVO> list = groupMsgService.getRecentGroupMsg(groupId);
        return getDataTable(list);
    }

    /**
     * 查询群历史消息
     *
     * @param condition 条件
     * @return {@link GroupMsgVO} 群聊天信息
     */
    @SaCheckLogin
    @ApiOperation(value = "查询群历史消息")
    @GetMapping(value = "/listHistory")
    public TableDataInfo listHistory(ConditionDTO condition) {
        startPage();
        List<GroupMsgVO> list = groupMsgService.selectGroupMsgVOList(condition);
        return getDataTable(list);
    }
}
